package com.miyake.server;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Blob;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.miyake.client.community.CommunityProperty;
import com.miyake.client.tools.ImageListElement;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class DsCommunity {
	@PrimaryKey 
	@Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)  
	private Key key;
	
	@Persistent
	private Integer type;
	
	@Persistent
	private String name;
	
	@Persistent
	private List<String> member = new ArrayList<String>();
	
	@Persistent
	private List<String> papers = new ArrayList<String>();
	
	@Persistent
	private DsImage image;

	public String getEncodedKey() {
		return KeyFactory.keyToString(key);
	}

	public void setKey(Key key) {
		this.key = key;
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<String> getMember() {
		return member;
	}

	public void setMember(List<String> member) {
		this.member = member;
	}
	
	public DsImage getImage() {
		return image;
	}

	public void setImage(DsImage image) {
		this.image = image;
	}

	public List<String> getPapers() {
		return papers;
	}

	public void setPapers(List<String> papers) {
		this.papers = papers;
	}

	public CommunityProperty toRemoteObject() {
		CommunityProperty ret = new CommunityProperty();
		ret.setKey(getEncodedKey());
		ret.setName(name);
		ret.setType(type);
		return ret;
	}

	public ImageListElement toCommunityProperty() {
		ImageListElement ret = new ImageListElement();
		if (image != null) {
			ret.setImageURL(image.toRemoteObject());
		}
		ret.setKey(getEncodedKey());
		return ret;
	}
	
}
